/*
 * Copyright (c) 1994-2017, Joyoung Stock CO.LTD.
 * The FWJR Project.
 * All Rights Reserved.
 */

package com.hepinghospital.user.ui.dialog;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;


import com.hepinghospital.user.R;
import com.hepinghospital.user.adapter.ReportReasonAdapter;
import com.hepinghospital.user.base.BaseDialogFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * 聊天举报弹框
 */
public class ReportDialog extends BaseDialogFragment {
    public static ReportDialog newInstance() {
        Bundle args = new Bundle();
        ReportDialog fragment = new ReportDialog();
        fragment.setArguments(args);
        return fragment;
    }

    private Dialog mDialog;
    private OnItemClickListener mListener;
    private TextView btn_confirm, btn_cancel, tv_reason_one, tv_reason_two, tv_reason_three, tv_reason_four;
    private RecyclerView recyclerView;
    private EditText etRefundReason;
    private List<String> datas = new ArrayList<>();
    private ReportReasonAdapter adapter;

    @SuppressLint("WrongViewCast")
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.dialog_report, container);
        btn_confirm = view.findViewById(R.id.btn_confirm);
        recyclerView = view.findViewById(R.id.recyclerView);
        etRefundReason = view.findViewById(R.id.et_refund_reason);

        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        datas.add("政治敏感");
        datas.add("广告骚扰");
        datas.add("人身攻击");
        datas.add("诈骗");
        adapter = new ReportReasonAdapter(datas);
        recyclerView.setAdapter(adapter);
        adapter.setOnItemClickListener((adapter1, view1, position) -> etRefundReason.setText(datas.get(position)));

//        btn_cancel = view.findViewById(R.id.btn_cancel);
//        btn_cancel.setOnClickListener(v -> {
//            if (mListener != null) {
//                mListener.onCancel();
//                dismiss();
//            }
//        });

        btn_confirm.setOnClickListener(v -> {
            if (mListener != null) {
                mListener.onConfirm(etRefundReason.getText().toString());
                dismiss();
            }
        });
        return view;
    }

    @Override
    @NonNull
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        mDialog = super.onCreateDialog(savedInstanceState);
        mDialog.setCancelable(false);
        Window window = mDialog.getWindow();
        if (window != null) {
            window.setGravity(Gravity.BOTTOM);
//            window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
//            window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        }
        return mDialog;
    }


    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
//        getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
        super.onActivityCreated(savedInstanceState);
        getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(0x00000000));
        getDialog().getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
    }

    public OnItemClickListener getmListener() {
        return mListener;
    }

    public void setmListener(OnItemClickListener mListener) {
        this.mListener = mListener;
    }


    public interface OnItemClickListener {

        void onConfirm(String reason);

        void onCancel();
    }

    public boolean isShowing() {
        return mDialog != null && mDialog.isShowing();
    }
}
